package org.aplombh.java.awcing.basic.dp.linearDP;

import java.io.*;
import java.util.Arrays;

/**
 * 给定一个长度为 N 的数列，求数值严格单调递增的子序列的长度最长是多少。
 * <p>
 * 输入格式
 * 第一行包含整数 N。
 * <p>
 * 第二行包含 N 个整数，表示完整序列。
 * <p>
 * 输出格式
 * 输出一个整数，表示最大长度。
 * <p>
 * 数据范围
 * 1≤N≤1000，
 * −109≤数列中的数≤109
 * 输入样例：
 * 7
 * 3 1 2 1 8 5 6
 * 输出样例：
 * 4
 */
public class LongestAscendingSubsequence_895 {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(reader.readLine());
        LongestAscendingSubsequence_1 longestAscendingSubsequence = new LongestAscendingSubsequence_1(n);
        String[] str = reader.readLine().split(" ");
        for (int j = 1; j <= n; j++) {
            longestAscendingSubsequence.w[j] = Integer.parseInt(str[j - 1]);
        }
        System.out.println(longestAscendingSubsequence.solve());
//        System.out.println(longestAscendingSubsequence.solve_1());
    }
}

class LongestAscendingSubsequence_1 {
    public static final int N = 100010;
    int n;
    int[] w = new int[N];
    int[] f = new int[N];

    public LongestAscendingSubsequence_1(int n) {
        this.n = n;
        Arrays.fill(f, 1);
    }

    public int solve() {
        int max_number_sub = -1 << 30;
        int max_sub = 1;
        for (int i = 1; i <= n; i++) {
            int max = -1 << 30;
            // 已j为结尾的最长公共子序列
            for (int j = i - 1; j > 0; j--) {
                if (max < f[j] + 1 && w[i] > w[j]) {
                    f[i] = f[j] + 1;
                    max = f[i];
                }
            }
            if (max > max_number_sub) {
                max_number_sub = max;
                max_sub = i;
            }
        }
        path(max_sub, max_number_sub);
        if (max_number_sub == -1 << 30)
            return 1;
        return max_number_sub;
    }

    public void path(int max_index_sub, int max_number_sub) {
        System.out.println(max_index_sub);
        for (int i = max_index_sub; i > 0; i--) {
            if (f[i] == max_number_sub) {
                for (int j = i - 1; j > 0; j--) {
                    if (f[i] == f[j] + 1 && w[i] > w[j]) {
                        System.out.print(j + " ");
                    }
                }
                max_number_sub--;
                System.out.println();
            }
        }
    }

    public int solve_1() {
        int res = -1 << 30;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j < i; j++) {
                if (w[i] > w[j]) {
                    f[i] = Math.max(f[i], f[j] + 1);
                }
            }
            if (f[i] > res) res = f[i];
        }
        return res;
    }
}
